public class Test16 {
    public int maxProfit(int[] prices, int fee) {
        int n = prices.length;
        int[] Buy = new int[n];
        int[] Tradable = new int[n];

        Buy[0] = -prices[0] - fee;
        for(int i = 1;i < n;i++) {
            Buy[i] = Math.max(Tradable[i - 1] - prices[i] - fee,Buy[i - 1]);
            Tradable[i] = Math.max(Buy[i - 1] + prices[i],Tradable[i - 1]);
        }
        return Tradable[n - 1];
    }
}
